// Evol scripts.
// Author:
//    Reid
//    Travolta
// Description:
//    Juscare, walking NPC of the legion of Aemil on the right part of the Agora of Artis.


function	script	JuscareTurnTo	{
    .@x = atoi(getarg(0));
    .@y = atoi(getarg(1));
    npc_turntoxy(.@x, .@y);
    return 0;
}


001-1,78,114,0	script	Juscare#001-1	NPC_HUMAN_MALE_LEGION_ARTIS,{

    function localClose {
        .dir = @Juscar_old_dir;
        npc_resumemove;
        close;
    }

    npc_pausemove;
    getmapxy(.@map$, .@cx, .@cy, 0);
    @Juscar_old_dir = .dir;
    npc_turntoxy(.@cx, .@cy);

    speech 4,
        l("It is a foggy day, don't you think?");

    localClose;

OnTimer100:
    if (!isunitwalking())
        movetonextpoint;
    initnpctimer;
    end;

OnInit:
    .sex = G_MALE;
    .distance = 4;
    // .debug = 1;
    initmovegraph
        "sector_1",     75,   111, 88,  117,
        "sector_2",     90,   110, 100, 116,
        "market_r",     68,   119, 73,  120,
        "market_m",     61,   115, 65,  121,
        "market_l",     49,   116, 57,  122,
        "secret",       36,   122, 40,  129;

    // flags: 0x1 -- moving from right to left, 0x2 -- moving from left to right

    // this is not very obvious stuff
    setmovegraphcmd
        "sector_1",     "sector_2",  1,  0x2,   "flags_0 2; flags_1 1; wait 50",
        "sector_2",     "sector_1",  1,  0x1,   "wait 50",
        "sector_1",     "market_r",  2,  0x1,   "flags_0 2; flags_1 1",
        "market_r",     "market_m",  1,  0x1,   "flags_1 3; wait 10; call JuscareTurnTo 57 117; wait 10",
        "market_r",     "sector_1",  1,  0x2,   "flags_1 3; dir 0; wait 50",
        "market_m",     "market_l",  1,  0x1,   "flags_0 2; wait 20; call JuscareTurnTo 57 117; wait 50",
        "market_m",     "market_r",  1,  0x2,   "flags_0 1; flags_1 2",
        "market_l",     "market_m",  5,  0x2,   "wait 10; call JuscareTurnTo 57 117; wait 30",
        "market_l",     "secret",    1,  0x1,   "flags_0 1; flags_1 2; wait 70",
        "secret",       "market_l",  1,  0x2,   "wait 10; call JuscareTurnTo 57 117; wait 40";

    firstmove "wait 1", "sector_1";
    initnpctimer;
}
